<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "good_right".
 *
 * @property int $id
 * @property string $item_name
 *
 * @property VipItem $item
 * @property Goods[] $goods
 */
class GoodRight extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'good_right';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['item_name'], 'required'],
            [['item_name'], 'string', 'max' => 64],
            [
                ['item_name'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => VipItem::className(),
                'targetAttribute' => ['item_name' => 'name']
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id'        => 'ID',
            'item_name' => 'Item Name',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getItem()
    {
        return $this->hasOne(VipItem::className(), ['name' => 'item_name']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGoods()
    {
        return $this->hasMany(Goods::className(), ['right' => 'id']);
    }


}

